<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *公告管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
if($_RQ['op']=='list'){
	
	$params=array('uniacid'=>$_SESSION['uniacid'],'storeid'=>$this->store_id);
	if(!empty($_RQ['name'])){
		$params['name like']='%'.trim($_RQ['name']).'%';
		$return['params']['name']=$_RQ['name'];
	}
	if(!empty($_RQ['storeid'])){
		$params['storeid']=intval($_RQ['storeid']);
		$return['params']['storeid']=$_RQ['storeid'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','uniacid','name','storeid','status');
	$list=pdo_getslice('jy_weishop_store_worker',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['store']=pdo_getcolumn('jy_weishop_store',array('id'=>$item['storeid']),'title');
			$item['sale']=pdo_getcolumn('jy_weishop_store_role',array('id'=>$item['roleid']),'sale_rate');
			if(!$item['sale']){
				$item['sale']=0;
			}
			$nowyue = mktime(0,0,0,date('m'),1,date('Y'));
			$yesyue = mktime(0,0,0,date('m')-1,1,date('Y'));
			$order=pdo_getall('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>3,'storeworkerid'=>$item['id']),array('price'));
			$totle=0;
			foreach($order as &$p){
				$totle +=$p['price'];
			}
			$item['totle']=$totle;
			$item['tsale']=$totle*$item['sale']/100;
			$order=pdo_getall('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>3,'storeworkerid'=>$item['id'],'finishtime >'=>$yesyue),array('price','finishtime'));
			$now=0;
			$yes=0;
			foreach($order as &$v){
			$yes +=	$v['price'];
			if($v['finishtime']>$nowyue){
				$now +=	$v['price'];
			}
			}
			$item['now']=$now*$item['sale']/100;
			$item['yes']=$yes*$item['sale']/100;
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		
		'list'=>array('data'=>'list','edit'=>false,'list'=>array(
			array('name'=>'name','title'=>'店员姓名','type'=>'string'),
			array('name'=>'store','title'=>'门店','type'=>'string'),
			array('name'=>'sale','title'=>'绩效比例（%）','type'=>'string'),
			array('name'=>'totle','title'=>'总成交金额','type'=>'string'),
			array('name'=>'tsale','title'=>'总绩效','type'=>'string'),
			array('name'=>'now','title'=>'当月绩效','type'=>'string'),
			array('name'=>'yes','title'=>'上月绩效','type'=>'string'),
		)),
		'search'=>array(
			array('name'=>'name','width'=>15,'title'=>'店员姓名','type'=>'string'),
			array('name'=>'storeid','width'=>15,'title'=>'选择门店','type'=>'select','options'=>'store'),
		)
		
		
	);
	$return['store']=pdo_getall('jy_weishop_store',array('uniacid'=>$_SESSION['uniacid']),array('id','title'));
	
	$return['htmls']=$htmls;
	
	exi($return);
}
